package com.dbxt.student.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.dbxt.dao.StudentMapper;
import com.dbxt.entity.ClerkRecord;
import com.dbxt.entity.Files;
import com.dbxt.entity.Record;
import com.dbxt.entity.RecordTeacher;
import com.dbxt.entity.Student;
import com.dbxt.student.service.StudentService;

@Service
@Transactional
public class StudentServiceImpl implements StudentService{
@Autowired 
private StudentMapper studentMapper;
@Override
public void upload(Files files,String fileName) {
	Files file = studentMapper.getFile(fileName);
	if(file!=null) {
		this.deleteFile(fileName);
		studentMapper.upload(files);
	}else {
	studentMapper.upload(files);
	}
}
@Override
public void deleteFile(String filename) {
	studentMapper.deleteFile(filename);
	
}
@Override
public List<Files> getFiles(Integer sid) {
	return studentMapper.getFiles(sid);
	
}
@Override
public boolean askforRecord(Integer sid,String group) {
	//申请答辩前进行判断是否答辩过
	Record recordBySid = studentMapper.getRecordBySid(sid);
	if(recordBySid!=null) {
		return false;
	}else {
		//没有答辩记录才能进行申请
		studentMapper.askforRecord(sid,group);
		return true;
	}
}
@Override
public boolean cancelApply(Integer sid) {
	//取消答辩申请查看是否有答辩记录
	Record recordBySid = studentMapper.getRecordBySid(sid);
	if(recordBySid==null) {
		//等于Null就是没答辩过，不能取消申请
		return false;
	}else {
		//不等于null表示有答辩记录则可以进行删除
		studentMapper.cancelApply(sid);
		return true;
	}
}
@Override
public Student checkResult(Integer sid) {
	return studentMapper.checkResult(sid);
}
@Override
public Record getRecordBySid(Integer sid) {
	return studentMapper.getRecordBySid(sid);
}
@Override
public List<Record> getGroupA(Integer tid) {
	return studentMapper.getGroupA(tid);
}
@Override
public List<Record> getGroupB(Integer tid) {
	return studentMapper.getGroupB(tid);
}
@Override
public Student selectByPrimaryKey(Integer sid) {
	return studentMapper.selectByPrimaryKey(sid);
}
@Override
public List<RecordTeacher> checkEvaluate(Integer sid) {
	return studentMapper.checkEvaluate(sid);
}
@Override
public void uploadPicture(Integer sid, String pictureName) {
	studentMapper.uploadPicture(sid, pictureName);
}
@Override
public List<RecordTeacher> getRecordTeacherByRid(Integer rid) {
	return studentMapper.getRecordTeacherByRid(rid);
}
@Override
public List<ClerkRecord> getClerkRecordByRid(Integer rid) {
	return studentMapper.getClerkRecordByRid(rid);
}
@Override
public List<Record> seeDefenceABOfA() {
	return studentMapper.seeDefenceABOfA();
}
@Override
public List<Record> seeDefenceABOfB() {
	return studentMapper.seeDefenceABOfB();
}
@Override
public String flushPicture(Integer sid) {
	return studentMapper.flushPicture(sid);
}
@Override
public List<Record> selectOnlyGroupA() {
	return studentMapper.selectOnlyGroupA();
}
@Override
public List<Record> selectOnlyGroupB() {
	return studentMapper.selectOnlyGroupB();
}
@Override
public void make(Integer rid) {
	studentMapper.make(rid);
	studentMapper.make2(rid);
}
@Override
public void delete(Integer rid) {
	studentMapper.delete2(rid);
	studentMapper.delete3(rid);
}
@Override
public void deleteFileByFileName(List<String> list) {
	studentMapper.deleteFileByFileName(list);
}
	 
}
